<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch">
      <el-form-item label="用户ID" prop="userId">
        <el-input v-model="queryParams.userId" placeholder="请输入用户ID" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="用户账号" prop="account">
        <el-input v-model="queryParams.account" placeholder="请输入用户账号" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="审核状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择审核状态" clearable size="small"
          @keyup.enter.native="handleQuery">
          <el-option v-for="item in statusOptions" :key="item.value" :label="item.dictLabel" :value="item.dictValue" />
        </el-select>
      </el-form-item>
      <el-form-item label="提现单号" prop="withdrawSn">
        <el-input v-model="queryParams.withdrawSn" placeholder="请输入提现单号" clearable size="small"
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="申请时间">
        <el-date-picker v-model="dateRange" type="daterange" align="right" value-format="yyyy-MM-dd" size="small"
          style="width: 230px" range-separator="-" start-placeholder="起始时间" end-placeholder="结束时间"
          :picker-options="pickerOptions">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="审核时间">
        <el-date-picker v-model="AuditdateRange" type="daterange" align="right" value-format="yyyy-MM-dd" size="small"
          style="width: 230px" range-separator="-" start-placeholder="起始时间" end-placeholder="结束时间"
          :picker-options="pickerOptions">
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索
        </el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置
        </el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="UserUploadTaskList" @selection-change="handleSelectionChange">
      <!-- <el-table-column type="selection" width="55" align="center" /> -->
      <el-table-column label="提现ID" align="center" prop="withdrawId" />
      <el-table-column label="提现单号" align="center" prop="withdrawSn" />
      <el-table-column label="用户信息" align="center">
        <template slot-scope="scope">
          <span>用户ID：{{ scope.row.userId }}</span>
          <br>
          <span>用户账号：{{ scope.row.account }}</span>
        </template>
      </el-table-column>
      <el-table-column label="审核状态" align="center" prop="status" :formatter="statusFormat" />
      <el-table-column label="提现金额" align="center" prop="withdrawAmt" />
      <el-table-column label="手续费" align="center" prop="serviceFee" />
      <el-table-column label="实际到账" align="center" prop="actualAmt" />

      <el-table-column label="账号信息" align="center" min-width="180rpx">
        <template slot-scope="scope">
          <span>户主：{{ scope.row.settleAcctNm }}</span><br />
          <span>卡号 ：{{ scope.row.settleAcct }}</span><br />
          <span>银行名：{{ scope.row.settleBankNm }}</span><br />
          <span>支行名：{{ scope.row.settleBranchNm }}</span>
          <br />
          <span>支行号：{{ scope.row.settleBankNo }}</span>

        </template>
      </el-table-column>
      <el-table-column label="申请时间" align="center" prop="createTime">
      </el-table-column>


      <el-table-column label="审核时间" align="center" prop="auditTime" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <!-- v-hasPermi="['admin:taskManage:taskuserlist:edit']" -->
          <el-button v-if="scope.row.status === 0" size="mini" type="text" icon="el-icon-check"
            @click="audit(scope.row, 1)">通过
          </el-button>
          <el-button v-if="scope.row.status === 0" size="mini" type="text" icon="el-icon-close"
            @click="audit(scope.row, 2)">拒绝
          </el-button>
        </template>
      </el-table-column>

    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body @close="cancel">
      <el-form ref="formRef" :model="form" label-width="80px">
        <el-form-item label="" prop="remark" :rules="{
          required: true,
          message: '请输入备注',
          trigger: 'blur',
        }">
          <el-input type="textarea" placeholder="请输入内容" maxlength="150" v-model="form.remark" show-word-limit
            :autosize="{ minRows: 6, maxRows: 6 }">
          </el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submit">{{ handBt }}</el-button>
          <el-button @click="cancel">取消</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>
<script>
import {
  getUserWithdrawPage,
  auditUserWithdraw,
} from "@/api/admin/user";
export default {
  name: "taskManage",
  data () {
    return {
      // 显示搜索条件
      showSearch: true,
      requestUrl: this.$img.requestUrl,
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userId: "",
        account: "",
        withdrawSn: "",
        status: "",
      },
      dateRange: [],
      AuditdateRange: [],
      // 总条数
      total: 0,
      loading: false,
      UserUploadTaskList: [],
      form: {},
      open: false,
      title: "",
      handBt: "",
      resource: "1",
      statusOptions: [
        {
          dictValue: 0,
          dictLabel: "待审核",
        },
        {
          dictValue: 1,
          dictLabel: "提现成功",
        },
        {
          dictValue: 2,
          dictLabel: "提现驳回",
        },
      ],
    };
  },
  created () {
    this.getList();
  },

  methods: {
    getList () {
      this.loading = true;
      let obj = this.addDateRange(this.queryParams, this.dateRange)
      let form = { ...obj, beginAuditTime: this.AuditdateRange[0] ? this.AuditdateRange[0] : "", endAuditTime: this.AuditdateRange[1] ? this.AuditdateRange[1] : "" }


      getUserWithdrawPage(form).then((response) => {

        this.UserUploadTaskList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },

    // 类型字典翻译
    appTypeFormat (row, column) {
      return this.selectDictLabel(this.statusOptions, row.auditStatus);
    },

    statusFormat (row, column) {
      console.log(row.status);
      return this.selectDictLabel(this.statusOptions, row.status);
    },

    audit (row, index) {
      let self = this;

      this.$confirm(
        "是否确认" +
        (index == 1 ? "通过" : "拒绝") +
        "《ID:" +
        row.userId +
        "》" +
        "提现审核?",
        "警告",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(function () {
          // this.$set(this.UserUploadTaskList, "status", 1)


          auditUserWithdraw({
            withdrawId: row.withdrawId,
            status: parseInt(index),
          }).then((response) => {
            self.msgSuccess(index == 1 ? "已通过" : "已拒绝");
            row.status = index;

          });
        })
        .catch(function () {
        });
    },

    //审核
    submit () {
      let self = this;
      this.$refs["formRef"].validate((valid) => {
        if (valid) {
          if (self.form.auditStatus === 1) {
            submitError({
              id: self.form.id,
              remark: self.form.remark,
            }).then((response) => {
              if (response.code == 200) {
                self.msgSuccess("操作成功");
                self.getList();
              }
            });
          } else {
            UserTaskAudit({
              id: self.form.id,
              auditStatus: -1,
              remark: self.form.remark,
            }).then((response) => {
              if (response.code == 200) {
                self.msgSuccess("操作成功");
                self.getList();
              }
            });
          }
          this.open = false;
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },

    // 取消按钮
    cancel () {
      this.open = false; //地址弹窗
    },

    // 多选框选中数据
    handleSelectionChange (selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    /** 搜索按钮操作 */
    handleQuery () {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery () {
      this.resetForm("queryForm");
      this.AuditdateRange = []
      this.dateRange = []
      this.handleQuery();
      this.getList();
    },
    handleView (row, index) {
      this.form = row;
      if (index == -1) {
        this.title = "审核拒绝";
        this.handBt = "拒绝";
      } else {
        this.title = "账号异常";
        this.handBt = "确定";
      }

      this.open = true;
    },
  },
};
</script>
<style scoped lang="scss"></style>
